#include "Disk.h"
namespace RayTracer
{
	bool Disk::Hit(const Ray & r, float t_min, float t_max, HitRecord & rec) const
	{
		vec3 N = normal;
		float D = glm::dot(N, position);
		float t = (D - glm::dot(r.origin(), N) / glm::dot(r.direction(), N));
		if (t > 0)
		{
			vec3 p = r.at(t);
			vec3 v = p - position;
			float d2 = dot(v, v);
			if (d2 <= radius * radius) 
			{
				if (t < t_min || t > t_max) return false;
				rec.t = t;
				rec.position = r.at(rec.t);
				rec.matPtr = this->matPtr;
				rec.set_face_normal(r, N);
				return true;
			}
			return false;
		}
		return false;
	}

}

